#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	int t;
	cin >> t;
	int n = 0, d, k;
	while (t--) {
		cin >> n >> d >> k;
		vector<vector<int>> arr(n + 10, vector<int>());
		for (int i = 0; i < k; i++) {
			int l, r;
			cin >> l >> r;
			arr[l].push_back(1);
			arr[r + 1].push_back(0);
		}
		int ans1 = 1, ans2 = 1;
		int l = 1, r = d;
		int sum = 0, cur = 0;
		for (int i = 1; i <= r; i++) {
			for (int j = 0; j < arr[i].size(); j++) {
				if (arr[i][j] == 1) sum++;
			}
		}
		cur = sum;
		l++, r++;
		while (r <= n) {
			if (cur > sum) {
				sum = cur;
				ans1 = max(1, r - d);
			}
			for (int j = 0; j < arr[r].size(); j++) {
				if (arr[r][j] == 1) cur++;
			}
			for (int j = 0; j < arr[l].size(); j++) {
				if (arr[l][j] == 0) cur--;
			}
			l++,r++;
		}
		if (cur > sum) {
			sum = cur;
			ans1 = max(1, r - d);
		}
		l = 1, r = d;
		sum = 0, cur = 0;
		for (int i = 1; i <= r; i++) {
			for (int j = 0; j < arr[i].size(); j++) {
				if (arr[i][j] == 1) sum++;
			}
		}
		cur = sum;
		l++, r++;
		while (r <= n) {
			if (cur < sum) {
				sum = cur;
				ans2 = max(1, r - d);
			}
			for (int j = 0; j < arr[r].size(); j++) {
				if (arr[r][j] == 1) cur++;
			}
			for (int j = 0; j < arr[l].size(); j++) {
				if (arr[l][j] == 0) cur--;
			}
			l++,r++;
		}
		if (cur < sum) {
			sum = cur;
			ans2 = max(1, r - d);
		}
		cout << ans1 << " " << ans2 << endl;
		arr.clear();
	}
	return 0;
}